import { h, render } from 'vue'
import MToast from './index.vue'
let vnode = null
function sleep(delay = 50) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve()
    }, delay)
  })
}
export default {
  show(text, delay = 1500) {
    if (vnode) return
    vnode = h(MToast, {
      text
    })
    render(vnode, document.body)
    setTimeout(async () => {
      vnode.el.style.opacity = '0'
      await sleep(1000)
      render(null, document.body)
      vnode = null
    }, delay)
  }
}
